package sailing.ui.model;

import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 * @author
 * 
 */
public class EditBtnCellRenderer implements TableCellRenderer {
	private int row;
	private int column;
	JButton editBtn, deleteBtn;
	private Object value;
	private static Insets margeInsets=new Insets(0,4,0,4);
	/**
	 * @param cbcb
	 * 
	 */
	public EditBtnCellRenderer(String editTxt, String deleteTxt) {
		editBtn = new JButton(editTxt);
		editBtn.setMargin(margeInsets);
		
		deleteBtn = new JButton(deleteTxt);
		deleteBtn.setMargin(margeInsets);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax .swing.JTable, java.lang.Object,
	 * boolean, boolean, int, int)
	 */
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {

		this.value = value;

		JPanel cellP = new JPanel();
		cellP.setLayout(new GridBagLayout());

		this.row = row;
		this.column = column;
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.anchor = GridBagConstraints.CENTER;
		
		Box box=Box.createHorizontalBox();
		box.add(editBtn);
		box.add(Box.createHorizontalStrut(10));
		box.add(deleteBtn);
		box.setBackground(Color.blue);
		cellP.add(box, c);
		if(isSelected){
			cellP.setBackground(table.getSelectionBackground());
		}else{
			cellP.setBackground(table.getBackground());
		}
		cellP.setBackground(table.getSelectionBackground());
		cellP.setOpaque(false);
		return cellP;
	}

}